*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*
* Diehl/Wolter: ATTITUDES ABOUT CONTAINMENT MEASURES DURING THE
*               2020/2021 CORONAVIRUS PANDEMIC:
*               SELF-INTEREST, OR BROADER POLITICAL ORIENTATIONS?
*
* Do-File for variable preparation of the spring 2020 wave
*
* This version: 20210430
*
* Author: Felix Wolter, felix.wolter@uni-konstanz.de
*
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

*Load Spring 2020 Kantar survey
use "kantarcovidratesmay.dta", clear
numlabel _all, add

*Generate empty sample variable existing only in wave 2
gen sample=.

*Wave (time) identifier
gen time = 0
label variable time "Time/wave"
label define time 0 "spring 2020" 1 "november 2020"
label value time time
tab time, mis

*Repair id variable
tab id, mis
sum id
replace id = _n+10000 if id==.

*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Dependent variable
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
tab1 masn1*, mis

foreach x of varlist masn1* {
	gen `x'rec = 11-`x'
}
tab1 *rec, mis

rename masn1arec openkitas
rename masn1brec openschools
rename masn1crec openrestau
rename masn1drec opencontact
rename masn1erec openborders
rename masn1frec openevents

pwcorr open*, sig
factor open* [aweight=gewicht], pcf blanks(.4)

factor open* [aweight=gewicht], pcf blanks(.4) mineigen(.89)
rotate, oblique oblimin blanks(.4)

alpha open*, item detail

*Generate index var of all 6 items
egen openindex = rowmean(open*)
tab openindex, mis

*z-standardize dependent variable
sum openindex [aweight=gewicht]
center openindex [aweight=gewicht], gen(zopenindex) double nolabel standardize
center openindex , gen(znowopenindex) double nolabel standardize

*Re-scale to five-point scale
tab1 openkitas-openevents, mis
foreach x of varlist openkitas-openevents{
   recode `x' (1 2=1) (3 4=2) (5 6=3) (7 8=4) (9 10=5), gen(`x'5)
}
tab1 open*5, mis

egen openindex5 = rowmean(open*5)
tab openindex5, mis

*z-standardize openkitas and openschools for robustness analysis
center openkitas [aweight=gewicht], gen(zopenkitas) double nolabel standardize
center openschools [aweight=gewicht], gen(zopenschools) double nolabel standardize

*Create opposition dummies for descriptive analysis
foreach x of varlist openkitas5-openevents5 {
    recode `x' (1/3=0) (4 5=1), gen(`x'dum)
}
tab1 *dum, mis


*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Independent variables
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Threats
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Sociotropic threat
tab1 masn2a-masn2h, mis
gen double sttwork = masn2a
gen double sttfinance = masn2b
gen double sttfamily = masn2c
gen double sttrights = masn2d

pwcorr stt*, sig
factor stt* [aweight=gewicht], pcf blanks(.4)
alpha stt*, item detail

*Create index variable
egen stt = rowmean(stt*)
tab stt, mis

*Subindizes
egen sttshort = rowmean(sttwork sttfinance sttfamily)
egen sttecon = rowmean(sttwork sttfinance)


*Individual threat
tab1 masn2e-masn2h, mis
gen double idtwork = masn2e
gen double idtfinance = masn2f
gen double idtfamily = masn2g
gen double idtrights = masn2h

pwcorr idt*, sig
factor idt* [aweight=gewicht], pcf blanks(.4)
alpha idt*, item detail

*Create index variable
egen idt = rowmean(idt*)
tab idt, mis

*Subindizes
egen idtshort = rowmean(idtwork idtfinance idtfamily)
egen idtecon = rowmean(idtwork idtfinance)

*Objective change in income due to corona
tab1 erw8b erw16, mis
gen double incloss = erw16==1 if erw16~=.
*replace incloss=0 if(erw2==4 |erw2==6) //Beamte and MFA have no loss
*replace incloss=0 if erw2==5
replace incloss=1 if(erw2==5 & (erw19==3 | erw19==4))
*replace incloss=0 if(erw1==8 | erw1==10) // Rentner and unemployed have no loss
tab incloss, mis


*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Political attitudes
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Left-Right-self positioning
tab inst4, mis  //too much missings, don't use this variable!
recast double inst4
recode inst4 (11 12 .= .), gen(leftright)
label var leftright "Left-Right-Self-Assess"
tab leftright, mis

gen double leftrightDK = inst4==11 if inst4~=.
gen double leftrightNR = inst4==12 if inst4~=.
gen double leftrightORIG = inst4
tab1 leftrightDK leftrightNR, mis

recode inst4 (0/3=1) (4/6=2) (7/10=3) (11/12=4), gen(leftrightcat)
label variable leftrightcat "Left-Right categorical"
label define lericat 1 "left" 2 "mid" 3 "right" 4 "DK and NR"
label value leftrightcat lericat
numlabel lericat, add
tab leftrightcat, mis

*Party preference
tab1 inst6*, mis
gen other = inst6_other~=".FILTER"
tab other, mis
replace inst6 = 7 if other==1
gen double partypref = inst6
label define inst5b 7 "keine/andere Partei", modify
label value partypref inst5b
tab partypref, mis
drop other


*Trust in institutions
tab1 inst1a, mis
rename inst1a trustbundesreg
rename inst1b trustbundestag
rename inst1c trustlandreg
rename inst1d trustparties
rename inst1e trusttelly
rename inst1f trustjournals
rename inst1g trustsocmed
rename inst1h trusthealthsys
rename inst1i trustpolice
rename inst1j trustscience

recast double trust*

factor trust* [aweight=gewicht], pcf blanks(.4)
rotate, oblique oblimin blanks(.4)  //two factors, state+science and media

*Test subdimensions for uni-dimensionality
factor trustbundes* trustland trustparties trusthealthsys trustpolice trustscience ///
   [aweight=gewicht] , pcf blanks(.4) //yep

factor trusttelly trustjournals trustsocmed ///
   [aweight=gewicht] , pcf blanks(.4)  //yep

*Reliability
alpha trustbundes* trustland trustparties trusthealthsys trustpolice trustscience, item detail
alpha trusttelly trustjournals trustsocmed, item detail  //social media problematic

*Generate index variables
egen truststate = rowmean(trustbundes* trustland trustparties trusthealthsys trustpolice trustscience)
egen trustmedia = rowmean(trusttelly trustjournals trustsocmed)
egen trustpress = rowmean(trusttelly trustjournals)
tab1 truststate trustmedia trustpress

gen doubtstate = 8-truststate
gen doubtmedia = 8-trustmedia
gen doubtpress = 8-trustpress
gen doubtsocmed = 8-trustsocmed


*How truthfully has the government informed?
tab inst3, mis
recast double inst3
gen doubtgovtruth = 6-inst3
tab doubtgovtruth, mis


*General trust
tab inst8, mis
recast double inst8
gen gentrust = inst8
tab gentrust, mis


*Communism cleavage, strong transfer state
tab umv4, mis
gen double protransfer = umv4
tab protransfer, mis


*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Covid risk group
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

*Trust in health system if infected
tab welf5, mis
recast double welf5
gen trusthsyscorona = 6-welf5
gen doubthsyscorona = welf5
tab1 trusthsyscorona doubthsyscorona, mis

*Risk group
tab ges4 , mis //problem: many refusals
gen float riskgroup01 = ges4 if(ges4~=9 & ges4~=.)
gen float riskgroup = ges4
gen float riskgroupmiss = ges4==9 if ges4~=.
tab1 riskgroup*, mis

*General health
tab ges1, mis
gen float health = 6-ges1 if ges1<6
tab health, mis

gen badhealth = 6-health
tab badhealth

*Contact with infected people
tab1 ges3*, mis
gen float contact = ges3
replace contact = 1 if (ges3_other~=" ")
tab contact, mis 


*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Sociodemographics and other
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Life satisfaction
tab zufr1, mis
gen double lsatisfac = zufr1
tab lsatisfac, mis

*Sex
tab stat1, mis
recast float stat1
recode stat1 (0=0) (1 2=1), gen(female)
label var female ""
tab female, mis

*Age
tab1 stat2*, mis
gen double age = 2020-stat2
tab age, mis

gen agedec = age/10

gen old = age>70
tab old, mis

*Eastern Germany
tab stat4 ost, mis //Berlin is grouped into Eastern, which we won't do
gen float east=ost
replace east=0 if stat4==3
tab stat4 east, mis
tab east

tab stat7, mis
recast float stat7
recode stat7 (1/3 5/7 9/12 15 17=0) (4 8 13 14 16 18 = 1) (.=.), gen(eastchild)
label var eastchild ""
tab stat7 eastchild, mis

*City vs. countryside
tab stat5, mis
gen float habitation = stat5
label value habitation stat5
tab habitation, mis

*Migration background
tab1 stat3*, mis nol
gen mig = 0 if (stat3a~=. & stat3b~=. & stat3c~=.)
replace mig = 1 if (stat3a==0 | stat3b==0 | stat3c==0)
replace mig=. if (stat3a==8 | stat3b==8 | stat3c==8)
tab mig, mis

*Children
tab stat12, mis
gen float children = stat12
tab children, mis

*Children at home
tab1 stat14 stat13, mis
gen float childrenathome = stat14>0 if stat14~=.
replace childrenathome = 0 if stat13==1
tab childrenathome, mis

*General education in years (nur only general education)
tab1 stat16*, mis
recast float stat16
recode stat16 (1=.) (2=7) (3=9) (4=10) (5=12) (6=13), gen(educgenyr)
tab1 stat17* educgenyr, mis

*General education categorical
gen float educgencat = stat16_gr3 
tab educgencat, mis
tab educgencat stat16, mis

*Vocational education in years
tab1 stat17 stat17_other, mis
recast float stat17
recode stat17 (1=1) (2=1) (3=3) (4=3) (5=0.5) (6=3) (7=3) (8=4) (9=4) (10=3) (11=0) (12=2), gen(educvocyr)
tab educvocyr , mis
tab stat18, mis
recast float stat18
recode stat18 (1=0) (2/5=2) (6=6) (7=1), gen(univyr)
tab stat17 univyr, mis
replace educvocyr = educvocyr+univyr if univyr<.
tab educvocyr, mis
drop univyr

*All education in years
gen educyr = educgenyr+educvocyr
tab educyr, mis

*Unemployed
tab1 erw1 erw15h, mis
gen float unemployed = erw1==8
replace unemployed = 1 if erw15h==1
tab unemployed, mis

*Partner
tab1 stat8 stat9, mis
gen float partner = (stat8==1 | stat8==2)
tab partner
replace partner=1 if stat9==1
tab partner, mis

*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Generate empty vars for November wave vars
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
gen eastaffil=.
gen fullossi=.
gen lagbehind=.


*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Recode infection rate variables
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
d kr*
sum kr_inz_rate kr_betr_rate kr_tod_md_kum
gen double kr_inz_rate10 = kr_inz_rate/10
gen double kr_tod_md_kum10 = kr_tod_md_kum/10

gen double kr_tod_rate = (kr_tod_md_kum*100000)/kr_population
gen double kr_tod_rate10 = (kr_tod_md_kum*10000)/kr_population

*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Save temporary dataset
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
gen float persweight = gewicht
save springdatatemp.dta, replace



